<template>
  <!-- 2. 准备一个具备宽高的DOM容器 -->
  <div ref="chart" class="chart" />
</template>

<script>
// 1. 引入escharts -> 记得下载 npm i echarts
import * as echarts from 'echarts'
// console.log('echarts', echarts) // undefined 说明：echarts库不是默认暴露
import resize from '@/mixins/resize'

export default {
  name: 'BarChart',
  mixins: [resize],
  mounted() {
    // 3. 创建echarts实例
    const myEcharts = echarts.init(this.$refs.chart)
    // 4. 定义option
    const option = {
      xAxis: {
        show: false,
        data: [
          '一月',
          '二月',
          '三月',
          '四月',
          '五月',
          '六月',
          '七月',
          '八月',
          '九月',
          '十月',
          '十一月',
          '十二月'
        ]
      },
      yAxis: {
        show: false
      },
      series: {
        type: 'bar',
        data: [20, 55, 44, 85, 78, 62, 99, 28, 70, 85, 78, 62]
      },
      grid: {
        top: 1,
        bottom: 0,
        left: 0,
        right: 0
      }
    }
    // 5. 生成图表
    myEcharts.setOption(option)

    this.myEcharts = myEcharts
  }
}
</script>

<style scoped>
.chart {
  width: 100%;
  height: 100%;
}
</style>
